/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util.www.sql;

/**
 *
 * @author Rdelacruz
 */
public class SelectSql {
    
    //obligatorios
    private String select;
    private String from;
    
    //opcionales
    private String join;
    private String groupby;
    private String whereHaving;
    private String orderby;
    
    public String getSql() {
        StringBuilder sb = new StringBuilder();
        sb.append(select);
        sb.append(" ");
        sb.append(from);
        
        if(join!=null) {
            sb.append(" ");
            sb.append(join);
        }
        if(groupby!=null) {
            sb.append(" ");
            sb.append(groupby);
        }
        if(whereHaving!=null) {
            sb.append(" ");
            sb.append(whereHaving);
        }
        if(orderby!=null) {
            sb.append(" ");
            sb.append(orderby);
        }
        return sb.toString();
    }
    
    public void agregarSelect(String select) {
        if(this.select!=null)
            this.select = this.select.concat(select);
        else
            this.select = select;
    }
    
    public void agregarJoin(String join) {
        if(this.join!=null)
            this.join = this.join.concat(" "+join);
        else
            this.join = join;
    }

    public String getSelect() {
        return select;
    }

    public void setSelect(String select) {
        this.select = select;
    }

    public String getFrom() {
        return from;
    }

    public void setFrom(String from) {
        this.from = from;
    }

    public String getJoin() {
        return join;
    }

    public void setJoin(String join) {
        this.join = join;
    }

    public String getGroupby() {
        return groupby;
    }

    public void setGroupby(String groupby) {
        this.groupby = groupby;
    }

    public String getWhereHaving() {
        return whereHaving;
    }

    public void setWhereHaving(String whereHaving) {
        this.whereHaving = whereHaving;
    }      

    public String getOrderby() {
        return orderby;
    }

    public void setOrderby(String orderby) {
        this.orderby = orderby;
    }
    
}
